package docmanager.business.objects;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;
import java.util.List;

import bf.DataAccess;

public class TipoDocumento extends BusinessObject {


	String descripcion;	
	boolean admiteSector;
	
	public static final int MANUAL_CALIDAD = 1;
	public static final int PROCEDIMIENTOS = 2;
	public static final int INSTRUCCIONES = 3;
	public static final int REGISTROS = 4;
	public static final int REGULACIONES = 5;

	public TipoDocumento(Connection conn, int id) throws SQLException
	    {
	      this.conn = conn;
	      this.id = id;
	      String query = "SELECT descripcion,admite_sector FROM tipos_documento WHERE id="+id;
	      ResultSet rs = DataAccess.selectQueryStatic(conn, query);
	      rs.next();
	      this.descripcion = rs.getString("descripcion");
	      int temp = rs.getInt("admite_sector");
	      if (temp == 1)
	      {
	          this.admiteSector = true;
	      }
	      else
	      {
	          this.admiteSector = false;
	      }
	    }
	
	public TipoDocumento(Connection conn, int id, String descripcion, boolean admiteSeccion)
	{
		this.id = id;
		this.conn = conn;
		this.descripcion = descripcion;
		this.admiteSector = admiteSeccion;
	}
	 
	
	public String getDescripcion() {
		return descripcion;
	}

	public void setDescripcion(String descripcion) {
		this.descripcion = descripcion;
	}

	public boolean isAdmiteSector() {
		return admiteSector;
	}

	public void setAdmiteSector(boolean admiteSeccion) {
		this.admiteSector = admiteSeccion;
	}


	
	@Override
	public void guardarNuevo(Connection conn) throws SQLException {
		// TODO Auto-generated method stub

	}

    public static List<TipoDocumento> obtenerTodosTipos(Connection conn) throws SQLException
    {
      String query = "SELECT id, descripcion, admite_sector FROM tipos_documento";
      List<TipoDocumento> l = new LinkedList<TipoDocumento>();
      ResultSet rs = DataAccess.selectQueryStatic(conn, query);
      while (rs.next())
      {
          int id = rs.getInt("id");;
          String descripcion = rs.getString("descripcion");
          int temp = rs.getInt("admite_sector");
          boolean as;
          if (temp == 1)
              as = true;
          else
              as = false;
          l.add(new TipoDocumento(conn,id,descripcion,as));
      }
      return(l);
    }

	
	
	
}
